package com.demo.springboot.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author wangfengchen
 * 字段自动填充
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private static final String FIELD_NAME_CREATE_TIME = "createTime";
    private static final String FIELD_NAME_UPDATE_TIME = "updateTime";


    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, FIELD_NAME_CREATE_TIME, Date.class, new Date());
        this.strictInsertFill(metaObject, FIELD_NAME_UPDATE_TIME, Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, FIELD_NAME_UPDATE_TIME, Date.class, new Date());
    }
}
